source(paste0("~/Desktop/Research/R/support_test/hawkes_utilities_timefactor.R"))
data_dir <- "~/Desktop/Research/lobster/"
save_dir <- "~/Desktop/Research/image_noise/"


model_config_list <- c("state_price_hawkes",                #1
                     "hawkes",                            #2
                     "state_price",                       #3
                     "state_hawkes",                      #4
                     "price_hawkes",                      #5
                     "state_price_hawkes_time30min",      #6
                    "state_price_hawkes_time5min",        #7
                    "state_hawkes_time5min",              #8
                    "state_hawkes_time_customizedone",       #9
                    "state_hawkes_time_customizedtwo",       #10
                    "state_hawkes_time_customizedthree",       #11
                    "state_hawkes_time1min")        #12

args <- commandArgs(trailingOnly=TRUE)
if(length(args) == 0){
  args_size <- 2
  model_config <- model_config_list[1]
}else{
  args_size <- as.numeric(args[1])
  model_config <-model_config_list[as.numeric(args[2])]
}

# "nosize" if arg is a even number; withsize" if arg odd number
if(args_size %% 2 == 0){
  config_size <- "nosize"
}else{
  config_size <- "withsize"
}


data_processed_dir <- paste0(save_dir, "/data_processed_", config_size, "/")
all_bigdt_files <- list.files(data_processed_dir)
all_bigdt_files <- all_bigdt_files[grep("rds", all_bigdt_files)]


#for(each_id in (100*args + 1):(100*args + 100)){
for (each_id in 1:20000){
  rds_file_name <- all_bigdt_files[each_id]
  
  file_path <- paste0(data_processed_dir, rds_file_name)
  out_dir <- paste0(save_dir, "/data_calculated_", config_size, "/")
  
  cat("input: ", file_path, "\n")
  cat("output: ", paste0(out_dir, "hawkes_kernel_single.",model_config, ".",rds_file_name), "\n")
  
  if(file.exists(paste0(out_dir, "hawkes_kernel_single.",model_config, ".",rds_file_name))){
    print("file exists!")
    next
  }
  
  bigdt <- readRDS(file_path)
  hawkes_kernel <- get_hawkes_kernel_bigdt(bigdt, model_config)
  dir.create(out_dir, showWarnings = FALSE)
  saveRDS(hawkes_kernel, paste0(out_dir, "hawkes_kernel_single.",model_config, ".",rds_file_name))
  
}
